<?php

namespace application\controller\cpservice;

use application\controller\cpservice\ServiceController;

class AuthorController extends ServiceController {

    private $administratorService;

    public function __construct() {
        parent::__construct();
        $this->administratorService = new \application\service\AdministratorService();
    }

    /**
     * Lấy Chức năng và hành động theo url
     * @mapping(value=cpservice/auth/signin.json)
     */
    public function signin() {
        $form = \core\system\HttpRequest::content('POST', 'json', \application\entity\db\Administrator::class);
        $resp = $this->administratorService->signin($form);
        if ($resp->success) {
            $this->session->administrator = $resp->data;
            $roles = $this->administratorService
                    ->getRoleByAdministratorId($this->session->administrator->id);
            $roleIds = array();
            foreach ($roles as $role) {
                $roleIds[] = $role->cpfunctionid;
            }
            $this->session->administratorRole = $roleIds;
        }
        $this->view->response($resp);
    }

}
